home *** CD-ROM | disk | FTP | other *** search
/ Enter 2006 February / enter-2006-02.iso / files / Illustrator_CS2_ue_TryOut.exe / bridge / Adobe Bridge 1.0.msi / Data1.cab / _7prefs.jsx < prev    next >
Encoding:
Text File  |  2005-03-24  |  8.9 KB  |  291 lines

  1. /**************************************************************************
  2. *
  3. *  @@@BUILDINFO@@@ 17prefs.jsx 1.0.0.54 25-Feb-2005
  4. *  Copyright 2005 Adobe Systems Incorporated
  5. *  All Rights Reserved.
  6. *
  7. * NOTICE:  All information contained herein is, and remains the property of
  8. * Adobe Systems Incorporated  and its suppliers,  if any.  The intellectual 
  9. * and technical concepts contained herein are proprietary to  Adobe Systems 
  10. * Incorporated  and its suppliers  and may be  covered by U.S.  and Foreign 
  11. * Patents,patents in process,and are protected by trade secret or copyright 
  12. * law.  Dissemination of this  information or reproduction of this material
  13. * is strictly  forbidden  unless prior written permission is  obtained from 
  14. * Adobe Systems Incorporated.
  15. **************************************************************************/
  16.  
  17. // Additions to the Prefs object.
  18.  
  19. // Initial preferences
  20. prefs.profileLevel = 0;            // Disable profiling by default
  21. prefs.profileTiming = false;    // Do not do timing by default
  22. prefs.profDisplayMode = 1;        // Show hit count by default (0 - nothing, 1 - hits, 2 - time)
  23. prefs.locale = $.locale;        // the default locale
  24.                                 // initial Data Browser preferences
  25. prefs.showFunctions = false;    // Controls the display of functions; set by the Functions context menu.
  26. prefs.showMethods = false;        // Controls the display of object methods; set by the Methods context menu.
  27. prefs.showPredefined = false;    // Controls the display of builtin predefined data; set by the Predefined context menu.
  28.                                 // Other preferences
  29. prefs.cleanWorkspace = false;    // Controls whether to start with a clean workspace
  30. prefs.dontBreakOnErrors = false;// set to true if runtime errors in try blocks should be ignored
  31. prefs.recentFiles = [];            // recently opened files
  32.  
  33. // The Prefs file is a file prefs.jsx located in the app data folder for the current user.
  34. // On Windows, this folder is C:\Documents and Settings\username\Application Data\Adobe\
  35. // ExtendScript Toolkit\1.0. On the Mac, this is /Users/username/Library/Application 
  36. // Support/Adobe/ExtendScript Toolkit/1.0. This folder is also available as app.configFolder.
  37.  
  38. // Load the file prefs.jsx during app startup.
  39.  
  40. prefs.load = function()
  41. {
  42.     var loaded = false;
  43.     var f = new File (app.configFolder + "/prefs.jsx");
  44.     if (f.exists)
  45.         loaded = app.load (f);
  46.     return loaded;
  47. }
  48.  
  49. // Create the parent folder if not yet present.
  50.  
  51. prefs.createFolder = function()
  52. {
  53.     var fld = new Folder (Folder.userData + "/Adobe");
  54.     if (!fld.exists)
  55.         fld.create();
  56.     fld = new Folder (fld + "/ExtendScript Toolkit");
  57.     if (!fld.exists)
  58.         fld.create();
  59.     fld = new Folder (fld + "/" + app.version);
  60.     if (!fld.exists)
  61.         fld.create();
  62.     return fld;
  63. }
  64.  
  65. // Save the file prefs.jsx during app shutdown.
  66.  
  67. prefs.save = function()
  68. {    
  69.     // set target and engine
  70.     prefs.target = currentDebugger.target;
  71.     prefs.engine = currentDebugger.engine;
  72.  
  73.     // create the prefs file
  74.     var fld = this.createFolder();
  75.     var f = new File (fld + "/prefs.jsx");
  76.     if (f.open ("w"))
  77.     {
  78.         f.write ("// ExtendScript Toolkit Preferences as of " + new Date().toString() + "\n\n");
  79.         f.write ("function readPrefs()\n{\n\tvar i, doc;\n");
  80.  
  81.         this._writeThis (f);
  82.         // the state of the console window
  83.         f.write ("\twindow.console.fontSize = " + window.console.fontSize + ";\n");
  84.         f.write ("\twindow.console.wrap = " + window.console.wrap + ";\n");
  85.  
  86.         // position and size of the main window
  87.         f.write ("\twindow.bounds = [" + window.normalizedBounds + "];\n");
  88.         f.write ("\twindow.maximized = " + window.maximized + ";\n");
  89.  
  90.         if (!prefs.cleanWorkspace)
  91.             this._writeDocs (f);
  92.  
  93.         this._writePaneInfo (f);
  94.         
  95.         // finally: the splitter positions
  96.         // needs to be at the end after all panes have been arranged
  97.         f.write ("\twindow.splitter = " + window.splitter + ";\n");
  98.         f.write ("\twindow.leftSplitters = [" + window.leftSplitters + "];\n");
  99.         f.write ("\twindow.rightSplitters = [" + window.rightSplitters + "];\n");
  100.         
  101.         if (document)
  102.         {
  103.             if (!prefs.cleanWorkspace)
  104.                 // set the current document
  105.                 f.write ('\tdocument = documents.find ("' + document.scriptID + '");\n');
  106.         }
  107.         f.write ("}\n\nreadPrefs();\n");
  108.         if (!f.close())
  109.             f.remove();
  110.     }
  111. }
  112.  
  113. // Document loader
  114. // This function attempts to load the document if the script ID is not bracketed
  115. // if bracketed, it just creates a new document. The method is called from within
  116. // the code generated by writeDocs()
  117.  
  118. function restoreDocument (scriptID, line1, selection)
  119. {
  120.     if (scriptID [0] == '/' || scriptID [0] == '~')
  121.     {
  122.         // must be a filespec
  123.         var f = new File (scriptID);
  124.         if (f.exists)
  125.         {
  126.             var doc = window.scripts.loadFile (f);
  127.             if (doc)
  128.             {
  129.                 // do not scroll, since we set the 1st visible line afterwards
  130.                 doc.setSelection (selection[0], selection[1], false);
  131.                 doc.firstVisibleLine = line1;
  132.             }
  133.         }
  134.     }
  135.     else
  136.         Document.create (scriptID);
  137. }
  138.  
  139. ////////////////////////////////////////////////////////////////////////////
  140. //                                Callbacks
  141. ////////////////////////////////////////////////////////////////////////////
  142.  
  143. // Called whenever the Prefs object changes. This can be quite often!
  144.  
  145. prefs.onChange = function (propertyName)
  146. {
  147.     if (currentDebugger
  148.      && propertyName == "scripts" 
  149.      && currentDebugger.target == BridgeTalk.appSpecifier)
  150.         currentDebugger.getScripts();
  151. }
  152.  
  153. ////////////////////////////////////////////////////////////////////////////
  154. //                                Helpers
  155. ////////////////////////////////////////////////////////////////////////////
  156.  
  157. // Write the prefs object
  158.  
  159. prefs._writeThis = function (f)
  160. {
  161.     // the prefs object
  162.     var props = this.reflect.properties;
  163.     for (var i = 0; i < props.length; i++)
  164.     {
  165.         var prop = props [i];
  166.         if (prop == "__proto__")
  167.             continue;
  168.  
  169.         f.write ("\tprefs." + prop.name + " = ");
  170.         var value = this [prop.name];
  171.         if (value == undefined)
  172.             continue;
  173.         // for now, write objects as toSource()
  174.         if (typeof value == "object")
  175.             f.write (value.toSource() + ";\n");
  176.         else
  177.         {
  178.             if (typeof value == "string")
  179.                 value = '"' + value.toString().replace (/"/g, '\\"') + '"';
  180.             else
  181.                 value = value.toString();
  182.             f.write (value + ";\n");
  183.         }
  184.     }
  185. }
  186.  
  187. // Write the list of documents along with the code to reload them.
  188. // Do not write any documents that contain scripts that were not loaded
  189. // from disk.
  190.  
  191. prefs._writeDocs = function (f)
  192. {
  193.     for (var i = 0; i < documents.length; i++)
  194.     {
  195.         var doc = documents [i];
  196.         // use either the path or the title
  197.         // when loading, a string starting with a slash indicates a path
  198.         if (doc.scriptID [0] == '/' || doc.scriptID [0] == '~')
  199.             f.write ('\trestoreDocument (\"' 
  200.                     + doc.scriptID 
  201.                     + '", ' 
  202.                     + doc.firstVisibleLine 
  203.                     + ', [' 
  204.                     + doc.getSelection()
  205.                     + ']);\n');
  206.         else if (doc.scriptID [0] == '(')
  207.             f.write ('\tDocument.create (\"' 
  208.                     + doc.title 
  209.                     + '", "", "' 
  210.                     + doc.scriptID
  211.                     + '");\n');
  212.         if (doc.scriptID [0] != '(')
  213.             doc.writeBP (f);
  214.     }
  215. }
  216.  
  217. // Write the locations of all panes.
  218. // this is more complicated, since the tabs need to be sorted in 
  219. // enclosure/dock/tab order - you can only append docks, not create 
  220. // empty ones
  221.  
  222. prefs._writePaneInfo = function (f)
  223. {
  224.     // sort the positional info by enclosure, dock and tab
  225.     function sortInfo (a, b)
  226.     {
  227.         var res = a[0] - b[0];
  228.         if (!res)
  229.             res = a[1] - b[1];
  230.         if (!res)
  231.             res = a[2] - b[2];
  232.         return res;
  233.     }
  234.  
  235.     // Collect the objects into infoArray, holding the pane info plus the object itself
  236.     var infoArray = [];
  237.     for (var i = 0; i < window.panes.length; i++)
  238.     {
  239.         var value = window.panes [i].paneInfo;
  240.         // add the object
  241.         value.push (window.panes [i]);
  242.         infoArray.push (value);
  243.     }
  244.     // now sort this array
  245.     infoArray.sort (sortInfo);
  246.     // make sure that all panes are hidden so we can rebuild the layout from scratch
  247.     f.write ("\tfor (i = 0; i < window.panes.length; i++)\n");
  248.     f.write ("\t\twindow.panes [i].visible = false;\n");
  249.     // and write the results
  250.     for (i = 0; i < infoArray.length; i++)
  251.     {
  252.         value = infoArray [i];
  253.         var obj = value.pop();
  254.         if (obj.constructor.name == "Document")
  255.         {
  256.             // a document pane
  257.             if (!prefs.cleanWorkspace)
  258.                 f.write ('\tdoc = documents.find ("' 
  259.                         + obj.scriptID 
  260.                         + '");\n'
  261.                         + '\tif (doc) doc.paneInfo = [' + 
  262.                         value + "];\n");
  263.         }
  264.         else
  265.         {
  266.             // a pane
  267.             f.write ("\tif (window." + obj.name + ")\n");
  268.             f.write ("\t\twindow." + obj.name + ".paneInfo = [" + value + "];\n");
  269.         }
  270.     }
  271.     // Select the previously selected panes
  272.     for (var i = 0; i < window.panes.length; i++)
  273.     {
  274.         obj = window.panes [i];
  275.         if (!(obj instanceof Document) && obj.selected)
  276.             f.write ("\twindow." + obj.name + ".selected = true;\n");
  277.     }
  278.     if (!prefs.cleanWorkspace)
  279.     {
  280.         for (i = 0; i < documents.length; i++)
  281.         {
  282.             obj = documents [i];
  283.             if (obj.selected)
  284.             {
  285.                 f.write ('\tdoc = documents.find ("' + obj.scriptID + '");\n');
  286.                 f.write ('\tif (doc) doc.selected = true;\n');
  287.             }
  288.         }
  289.     }
  290. }
  291.